package com.yujian.weixin;
import org.weixin4j.message.normal.TextInputMessage;
import org.weixin4j.message.normal.ImageInputMessage;
import org.weixin4j.message.normal.LinkInputMessage;
import org.weixin4j.message.normal.LocationInputMessage;
import org.weixin4j.message.normal.NormalMessage;
import org.weixin4j.message.normal.ShortVideoInputMessage;
import org.weixin4j.message.normal.VideoInputMessage;
import org.weixin4j.message.normal.VoiceInputMessage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.weixin4j.message.Articles;
import org.weixin4j.message.OutputMessage;
import org.weixin4j.message.output.NewsOutputMessage;
import org.weixin4j.message.output.TextOutputMessage;
import org.weixin4j.spi.INormalMessageHandler;

import com.yujian.functions.Weather;

public class CustomNormalMessageHandler implements INormalMessageHandler {
	 protected static final String LINE_SEPARATOR = System.getProperty("line.separator");
	 private final static Map<String,String> maps = new HashMap<String, String>();
	 private final static Map<String,String> buttonMaps = new HashMap<String, String>();   
	    static{
	    	maps.put("开发者", "刘宇健");
	        maps.put("电话", "17722799521");
	        maps.put("主页", "http://www.l-yj.cn/Galois/");
	        maps.put("习惯","1、健身"+LINE_SEPARATOR+"2、敲码"+LINE_SEPARATOR+"3、7点"+LINE_SEPARATOR+"4、极端心理健康"+LINE_SEPARATOR+"回复相应名词查看更多信息");
	        maps.put("博客", "http://blog.csdn.net/galoislyj/article/list/1");
	        buttonMaps.put("BTN-1", "点我送祝福");
	        buttonMaps.put("BTN-2","我的主页");
	        buttonMaps.put("BTN-3","我的积分");
	    }
	
    private OutputMessage allType(NormalMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("功能还在完善中哦~");
        return out;
    }

    @Override
    public OutputMessage textTypeMsg(TextInputMessage msg) {
    	if(maps.containsKey(msg.getContent())){
            String value = maps.get(msg.getContent());
            return new TextOutputMessage(value);
        }
    	if(msg.getContent().equals("天气")){
    		Weather we = new Weather();
    		return new TextOutputMessage(we.getTodayWeather());
    	}
    	
    	if(msg.getContent().equals("健身")){
    		
    		//实例化一个图文消息
            NewsOutputMessage newsOutputMsg = new NewsOutputMessage();
            List<Articles> list = new ArrayList<Articles>();
            
            Articles articles = new Articles();
            articles.setTitle("Galois的生活习惯系列之健身!");
            articles.setPicUrl("http://www.l-yj.cn/yujian/images/bas.jpg");
            articles.setUrl("http://www.l-yj.cn/yujian/fit.html");
            list.add(articles);
            
            Articles articles2 = new Articles();
            articles2.setTitle("饮食篇~!	:)");
            articles2.setDescription("健康美丽吃啥哟，广工水上大饭堂;坚持去饭堂吃饭,少吃垃圾食品");
            articles2.setPicUrl("http://www.l-yj.cn/yujian/images/food.jpg");
            articles2.setUrl("http://www.l-yj.cn/yujian/food.html");
            list.add(articles2);
            
            Articles articles3 = new Articles();
            articles3.setTitle("训练篇~!	:)");
            articles3.setDescription("每一个强大的人,都咬着牙度过一段没人帮忙、没人支持、没人嘘寒问暖的日子。过去了，这就是你的成人礼，过不去，这就是你的无底洞。");
            articles3.setPicUrl("http://www.l-yj.cn/yujian/images/g.jpg");
            articles3.setUrl("http://www.l-yj.cn/yujian/keep.html");
            list.add(articles3);
            
            //一条图文消息
            newsOutputMsg.setArticles(list);
            return newsOutputMsg;
            
    	}
    	
    	if(msg.getContent().equals("敲码")){
    		//实例化一个图文消息
            NewsOutputMessage newsOutputMsg = new NewsOutputMessage();
            List<Articles> list = new ArrayList<Articles>();
            Articles articles = new Articles();
            articles.setTitle("Galois的生活习惯系列之敲码!");
            articles.setDescription("我码我人生。用自己的热情，创造自己的作品，这是我的世界，我为自己代言。");
            articles.setPicUrl("http://www.l-yj.cn/yujian/images/me.jpg");
            articles.setUrl("http://www.l-yj.cn/yujian/code.html");
            list.add(articles);
            //一条图文消息
            newsOutputMsg.setArticles(list);
            return newsOutputMsg;
    	}
    	
    	if(msg.getContent().equals("7点")){
    		//实例化一个图文消息
            NewsOutputMessage newsOutputMsg = new NewsOutputMessage();
            List<Articles> list = new ArrayList<Articles>();
            Articles articles = new Articles();
            articles.setTitle("Galois的生活习惯系列之7点!");
            articles.setDescription("用每一个7点，换每一天紧凑；拒绝松松垮垮碌碌无为的生活，拥抱兢兢业业默默耕耘的高三");
            articles.setPicUrl("http://img4.imgtn.bdimg.com/it/u=3884661623,3754846005&fm=23&gp=0.jpg");
            articles.setUrl("http://www.l-yj.cn/yujian/seven.html");
            list.add(articles);
            //一条图文消息
            newsOutputMsg.setArticles(list);
            return newsOutputMsg;
    	}
    	
    	if(msg.getContent().equals("极端心理健康")){
    		//实例化一个图文消息
            NewsOutputMessage newsOutputMsg = new NewsOutputMessage();
            List<Articles> list = new ArrayList<Articles>();
            Articles articles = new Articles();
            articles.setTitle("自我实现者");
            articles.setDescription("马斯洛发现真正达到自我实现的人，一般都处于中年或老年，年轻的人通常很难达到自我实现。这是因为年轻人还有许多较低层次的需要，如安全、爱、自尊等等还没有得到适当程度的满足，没有形成持久的价值观、智慧、意志力及稳定的爱情关系，也未明确选择自己要为之终身奋斗的事业。不过，年轻人具有极大的发展潜力，他们通过积极努力，是可以逐渐接近这一水平或目标的。通过对以上案例的研究，马斯洛归纳出\"自我实现者\"的15种心理特征：");
            articles.setPicUrl("http://img3.imgtn.bdimg.com/it/u=1834037979,452851062&fm=23&gp=0.jpg");
            articles.setUrl("https://www.douban.com/note/580745224/");
            list.add(articles);
            //一条图文消息
            newsOutputMsg.setArticles(list);
            return newsOutputMsg;
    	}
    	
    	//如果接收的是未定义的文本消息，就发送一个weixin4j的图文消息
        //实例化一个图文消息
        NewsOutputMessage newsOutputMsg = new NewsOutputMessage();
        List<Articles> list = new ArrayList<Articles>();
        Articles articles = new Articles();
        articles.setTitle("欢迎使用weixin4j微信开发包!");
        articles.setDescription("为Java微信开发爱好者提供的微信公众开发平台SDK，简化了Java对微信的开发。");
        articles.setPicUrl("http://files.colabug.com/forum/201504/26/151806nahhqqh7p4pxlqxs.jpg");
        articles.setUrl("http://www.weixin4j.org");
        list.add(articles);
        //一条图文消息
        newsOutputMsg.setArticles(list);
        return newsOutputMsg;
    }

    @Override
    public OutputMessage imageTypeMsg(ImageInputMessage msg) {
        return allType(msg);
    }

    @Override
    public OutputMessage voiceTypeMsg(VoiceInputMessage msg) {
        return allType(msg);
    }

    @Override
    public OutputMessage videoTypeMsg(VideoInputMessage msg) {
        return allType(msg);
    }

    @Override
    public OutputMessage shortvideoTypeMsg(ShortVideoInputMessage msg) {
        return allType(msg);
    }

    @Override
    public OutputMessage locationTypeMsg(LocationInputMessage msg) {
        return allType(msg);
    }

    @Override
    public OutputMessage linkTypeMsg(LinkInputMessage msg) {
        return allType(msg);
    }
}